package cn.kgc.vue.commons;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;

@Data
public class ResponseResult {
    @ApiModelProperty(value = "状态码",required = true,example = "0")
    private Integer code;
    @ApiModelProperty(value = "提示信息",required = true,example = "操作成功")
    private String message;
    @ApiModelProperty(value = "返回数据",required = true,example = "{pageData：{}}")
    private HashMap<String, Object> data=new HashMap<>();


    private ResponseResult() {}
//成功
    public static ResponseResult success() {
        ResponseResult responseResult=new ResponseResult();
        responseResult.code = ResponseStatus.SUCCESS.getCode();
        responseResult.message = ResponseStatus.SUCCESS.getMsg();
        return responseResult;
    }

    //失败
    public static ResponseResult fail() {
        ResponseResult responseResult = new ResponseResult();
        responseResult.code = ResponseStatus.FAIl.getCode();
        responseResult.message = ResponseStatus.FAIl.getMsg();
        return responseResult;
    }


    //异常
    public static ResponseResult error() {
        ResponseResult responseResult=new ResponseResult();
        responseResult.code = ResponseStatus.ERROR.getCode();
        responseResult.message = ResponseStatus.ERROR.getMsg();
        return responseResult;
    }


    //message
    public ResponseResult message(String message) {
        this.message=message;
        return this;
    }

    //code
    public ResponseResult code(Integer code) {
        this.code=code;
        return this;
    }

    //data
    public ResponseResult data(String key,Object value) {
        data.put(key, value);
        return this;
    }

}
